<%@ Page Language="C#" Theme="Defaultsys" AutoEventWireup="true" CodeFile="ContactGroup.aspx.cs"
    Inherits="ContactGroup" Title="Rapport Plan System - Contact group" MasterPageFile="~/MasterPage.master" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content runat="server" ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1">

    <script type="text/javascript" language="javascript">
    
    function RefreshGroup()
    {
        var groupList = document.getElementById("ctl00_ContentPlaceHolder1_lstGroupContacts");
        var hidden = document.getElementById("ctl00_ContentPlaceHolder1_txtGroupContactIds");
        hidden.value = "";
        
        for (i=groupList.options.length-1; i>=0 ; i--)
        {
            hidden.value += groupList.options[i].value  + ";";
        }
    }
    
    function MoveToGroup()
    {    
        var list = document.getElementById("ctl00_ContentPlaceHolder1_lstContacts");
        var groupList = document.getElementById("ctl00_ContentPlaceHolder1_lstGroupContacts");
       
    
        for (i=list.options.length-1;i>=0; i--)
        {            
           if (list.options[i].selected)
            {
                var o = document.createElement("option");
                o.text = list.options[i].text;
                o.value = list.options[i].value;
                
                try 
                {
                    groupList.add(o,null);
                    list.remove(i,null);
                }
                catch(ex) 
                {
                    groupList.add(o);
                    list.remove(i);
                }
                
            }
            
        }

        RefreshGroup();
        return false;        
    }
    
    function RemoveFromGroup()
    {
        var list = document.getElementById("ctl00_ContentPlaceHolder1_lstContacts");
        var groupList = document.getElementById("ctl00_ContentPlaceHolder1_lstGroupContacts");
        
        for (i=groupList.options.length-1; i>=0 ; i--)
        {
            if (groupList.options[i].selected)
            {
                var o = document.createElement("option");
                o.text = groupList.options[i].text;
                o.value = groupList.options[i].value;
                
                
                try 
                {
                    list.add(o,null);
                    groupList.remove(i,null);
                }
                catch(ex) 
                {
                    list.add(o);
                    groupList.remove(i);
                }
            }
        }
        
        RefreshGroup();
        return false;        
    }
    
     function MoveAllToGroup()
    {    
        var list = document.getElementById("ctl00_ContentPlaceHolder1_lstContacts");
        var groupList = document.getElementById("ctl00_ContentPlaceHolder1_lstGroupContacts");
       
    
        for (i=list.options.length-1;i>=0; i--)
        {            
            var o = document.createElement("option");
            o.text = list.options[i].text;
            o.value = list.options[i].value;
            
            try 
            {
                groupList.add(o,null);
                list.remove(i,null);
            }
            catch(ex) 
            {
                groupList.add(o);
                list.remove(i);
            }
        }
        
        RefreshGroup();
        return false;        
    }
    
    function RemoveAllFromGroup()
    {
        var list = document.getElementById("ctl00_ContentPlaceHolder1_lstContacts");
        var groupList = document.getElementById("ctl00_ContentPlaceHolder1_lstGroupContacts");
        
        for (i=groupList.options.length-1; i>=0 ; i--)
        {
            var o = document.createElement("option");
            o.text = groupList.options[i].text;
            o.value = groupList.options[i].value;
            
            
            try 
            {
                list.add(o,null);
                groupList.remove(i,null);
            }
            catch(ex) 
            {
                list.add(o);
                groupList.remove(i);
            }
        }
        
        RefreshGroup();
        return false;        
    }
    
    </script>

    <table border="0" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <td class="contTable">
                <table>
                    <tr>
                        <td>
                            Group name:
                        </td>
                        <td>
                            <asp:TextBox ID="txtContactGroupName" runat="server" MaxLength="255" Width="227px"></asp:TextBox>
                            <asp:Label ID="lblSteluta" runat="server" ForeColor="Red" Text="*" Visible="False"></asp:Label></td>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtContactGroupName"
                                CssClass="error" ErrorMessage="First Name is required" SetFocusOnError="True"
                                Display="Dynamic">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Contacts:</td>
                        <td>
                            <table border="0">
                                <tr>
                                    <td>
                                        <asp:ListBox ID="lstContacts" runat="server" Width="236px" SelectionMode="Multiple"
                                            Rows="20">
                                            <asp:ListItem>Contact 1</asp:ListItem>
                                            <asp:ListItem>Contact 2</asp:ListItem>
                                            <asp:ListItem>Contact 3</asp:ListItem>
                                            <asp:ListItem></asp:ListItem>
                                        </asp:ListBox>
                                    </td>
                                    <td>
                                        <asp:Button ID="btnMoveAllToGroup" runat="server" Text="  >>  " /><br />
                                        <asp:Button ID="btnMoveToGroup" runat="server" Text="   >   " /><br />
                                        <asp:Button ID="btnRemoveFromGroup" runat="server" Text="   <   " />&nbsp;<br />
                                        <asp:Button ID="btnRemoveAllFromGroup" runat="server" Text="  <<  " />
                                    </td>
                                    <td>
                                        <asp:ListBox ID="lstGroupContacts" runat="server" Width="236px" SelectionMode="Multiple"
                                            Rows="20"></asp:ListBox>
                                    </td>
                                </tr>
                            </table>
                            <asp:HiddenField ID="txtGroupContactIds" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td align="left" colspan="2">
                            <asp:Button ID="btnSave" runat="server" OnClick="Save" Text="Save" />
                            <asp:Button ID="btnCancel" runat="server" OnClick="Cancel" Text="Cancel" CausesValidation="false" /><br />
                            <asp:Label ID="lblContactGroupSaved" runat="server" ForeColor="#FF8000" Text="The contact group was saved sucessfully"
                                Visible="False"></asp:Label></td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtContactGroupName"
                                CssClass="error" ErrorMessage="(*)Group Name is required" SetFocusOnError="True"
                                Display="Dynamic"></asp:RequiredFieldValidator>
                            <asp:Label ID="lblGroupExist" runat="server" ForeColor="Red" Text="(*)Group name already exist"
                                Visible="False" Width="182px"></asp:Label>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>
